 #! /usr/bin/env python
"""
Convert a single image file sequence to a QuickTime movie.

Author: Chip Chapin <cchapin@gmail.com>
For More Info: http://code.google.com/p/seq-to-qt/
Latest Update: 2010-02-03
"""
import os
import seq_to_qt

DEFAULT_CHUNK_SIZE = 7000
DEFAULT_FRAME_RATE = "60"

def usage(message=None):
    """Print usage message and exit."""
    if message:
        print message
    print "Usage: seq_convert.py sequenceFile [maxSize [frameRate]]"
    print (
"\nSequences have sequentially numbered file names like\n" +
"    Foo-001.jpg, Foo-002.jpg...\n" +
"sequenceFile -- Path to any file in the sequence.\n" +
"maxSize -- Maximum number of sequence files to put in a folder.");
    sys.exit(2)
   
def main(argv):
    """Main Program"""
    if len(argv) < 2:
        usage("Expected at least one argument")
    seq_path = os.path.abspath(argv[1])
    max_size = DEFAULT_CHUNK_SIZE
    frame_rate = DEFAULT_FRAME_RATE
    if len(argv) >= 3:
        max_size = float(argv[2])
        if len(argv) >= 4:
            frame_rate = argv[3]    

    (seq_dir, seq_file) = os.path.split(seq_path)
    print "sqd " + seq_dir
    print "sqf " + seq_file
    
    # Base directory.  This is the parent of the sequence directory
    base_path = os.path.dirname(seq_dir)
    print "bp " + base_path

    # Image sequences.
    # A sequence is a duple containing the
    # FOLDER NAME and the STARTING IMAGE of the sequence
    sequence =  [(os.path.basename(seq_dir), seq_file)]

    # Now do the conversion.
    seq_to_qt.convert_sequences(base_path,
                                sequence,
                                frame_rate,
                                max_size)
    
if __name__ == "__main__":
    import sys
    main(sys.argv)
